
//
//  JYMineHeaderView.m
//  JYFarm
//
//  Created by 花花 on 2017/10/11.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYMineHeaderView.h"
#import "JYButton.h"
@interface JYMineHeaderView()
//头像
@property(nonatomic)UIImageView *headerImage;
//商家名称
@property(nonatomic)UILabel *shopName;
//手机号
@property(nonatomic)UILabel *phoneLabel;
//bgView
@property(nonatomic)UIImageView *bgView;
@end

@implementation JYMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        [ self setupSubView];
    }
    return self;
    
}
- (void)setupSubView{

    [self addSubview:self.bgView];
    [self.bgView addSubview:self.headerImage];
    
    [self.bgView addSubview:self.shopName];
    [self.bgView addSubview:self.phoneLabel];
    
}

- (void)layoutSubviews{

    [super layoutSubviews];
    JYWeakSelf;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.width.mas_equalTo(weakSelf.mas_width);
        make.height.mas_equalTo(weakSelf.mas_height);
    }];
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(64);
        make.width.height.mas_equalTo(80);
        
    }];
    [self.shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.headerImage.mas_right).offset(12);
        make.top.mas_equalTo(weakSelf.headerImage.mas_top).offset(20);
        
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.headerImage.mas_right).offset(12);
        make.top.mas_equalTo(weakSelf.shopName.mas_bottom).offset(12);
    }];

}
- (UIImageView *)headerImage{

    if (!_headerImage) {
        _headerImage = [[UIImageView alloc]init];
        _headerImage.image =[UIImage imageNamed:@"mine_portrait"];
        _headerImage.layer.masksToBounds =YES;
        _headerImage.layer.cornerRadius = 40;
        _headerImage.layer.borderColor =[UIColor whiteColor].CGColor;
        _headerImage.layer.borderWidth = 1;
    }
    return _headerImage;
}
- (UILabel *)shopName{

    if (!_shopName) {
        _shopName = [UILabel labelText:[[NSUserDefaults standardUserDefaults] objectForKey:kMerchantName] fontSize:17 textColor:kfColor textAlignment:NSTextAlignmentCenter];
    }
    return _shopName;
}
- (UILabel *)phoneLabel{

    if (!_phoneLabel) {
        NSString * text = [NSString stringWithFormat:@"手机号: %@", [[NSUserDefaults standardUserDefaults] objectForKey:kAccount]];
        _phoneLabel = [UILabel labelText:text fontSize:14 textColor:kfColor textAlignment:NSTextAlignmentCenter];
    }
    return _phoneLabel;

}
- (UIImageView *)bgView{

    if (!_bgView) {
        _bgView = [[UIImageView alloc]init];
        _bgView.image = [UIImage imageNamed:@"headerBg"];
    }
    return _bgView;
}
@end


@interface JKFuncationView()
//头像
@property(nonatomic)UIImageView *headerImage;
//商家名称
@property(nonatomic)UILabel *shopName;
//手机号
@property(nonatomic)UILabel *phoneLabel;

@end

@implementation JKFuncationView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self setupSubView];
        
        
    }
    return self;

}
- (void)setupSubView{
         CGFloat btnW =   (Screen_Width-30 - 3) / 4;
//    for (int i = 1; i< 4; i++) {
//        
//        UILabel *label = [UILabel labelText:@"" fontSize:17 textColor:kThemeColor textAlignment:NSTextAlignmentCenter];
//        label.frame = CGRectMake(15+i*(btnW+1), (self.height-25)/2, 1, 25);
//        label.backgroundColor =  kSeparatedLineColor;
//        [self addSubview:label];
//    }


    CGFloat linW = IS_IPHONE_5?0.5:1;
    CGFloat btnH = 40;
    NSArray *titleArr = @[@"待付款",@"待发货",@"待收货",@"已完成"];
    NSArray *imgArr = @[@"mine_pay",@"mine_shipping",@"mine_the_goods",@"mine_to_complete"];
    for(int i = 0;i<titleArr.count;i++){
        UIButton *btn = [[JYButton alloc]initWithFrame:CGRectMake(15+i*(btnW+1), 10, btnW, btnH)];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
        btn.titleLabel.font = kFont(12);
        btn.tag = i+1;
        [btn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:k9Color forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal];

        [self addSubview:btn];
        
        if (i >= 0 && i<titleArr.count-1) { // 添加间隔竖线   w为1就会有点朦胧的效果
            UIView *line = [[UIView alloc] init];
            
            line.frame = CGRectMake(CGRectGetMaxX(btn.frame), (self.height-25)/2, linW, 25);
            line.backgroundColor = kSeparatedLineColor;
            [self addSubview:line];
        }
        
    
    }
    
}
- (void)btnOnClick:(UIButton *)btn{

    if (_handlerBtnOnClick) {
        _handlerBtnOnClick(btn.tag);
    }
}
@end

